import java.util.Random;
import java.util.concurrent.FutureTask;

/**
 * 在主线程中创建两个子线程，每个子线程中产生一个随机数，最终等待子线程执行完之后
 * 在主线程累计两个子线程的结果
 */
public class ThreadDemo_数组求和 {
    static int num1 = 0;
    static int num2 = 0;
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            num1 = new Random().nextInt(10);
        });
        t1.start();
        Thread t2 = new Thread(() -> {
            num2 = new Random().nextInt(10);
        });
        t2.start();

        t1.join();
        t2.join();
        System.out.println(num1 + num2);
    }

}
